package com.zyb.patient.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.annotation.SuppressLint;

public class DateUtil {
	/**
	 * 时间戳换算xxx前 **
	 */
	@SuppressLint("SimpleDateFormat")
	public static String getTimeGap3(String beg, Date now) {
		try {
			SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String beginDate = TimeStamp3Date(beg);
			Date begin = dfs.parse(beginDate);
			// System.out.println("beginDate:"+ beginDate);
			// System.out.println("begin:"+ begin);
			String endData = dfs.format(now);
			Date end = dfs.parse(endData);
			long between = (end.getTime() - begin.getTime()) / 1000;// 除以1000是为了转换成秒
			long second = between;
			if (second < 60) {
				return "1分钟前";
			} else if (second < (60 * 60)) {
				long minute = between / 60;
				return minute + "分钟前";
			} else if (second < (24 * 60 * 60)) {
				long hour = between / 3600;
				return hour + "小时前";
			} else if (second < (30 * 24 * 60 * 60)) {
				long day = between / (24 * 3600);
				return day + "天前";
			} else if (second < (12 * 30 * 24 * 60 * 60)) {
				long month = between / (30 * 24 * 3600);
				return month + "月前";
			} else {
				long year = between / (12 * 30 * 24 * 3600);
				return year + "年前";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static String TimeStamp3Date(String timeString) {
		Long timestamp = Long.parseLong(timeString) * 1000;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date = sdf.format(new java.util.Date(timestamp));
		return date;
	}

	
	  public static String getCurrentTime() {
	        String returnStr = null;
	        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	        Date date = new Date();
	        returnStr = f.format(date);
	        return returnStr;
	    }
	  
	  public static String getTime(long time) {
		   Date currentTime = new Date(time);
		   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		   String dateString = formatter.format(currentTime);
		   return dateString;
		}
	  
	  public static String getTime2(long time) {
		   Date currentTime = new Date(time);
		   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		   String dateString = formatter.format(currentTime);
		   return dateString;
		}
}
